/**
 * 后台类目管理
 */
const express = require('express')
const mytopic = require('../../middleware/mytopic')

const mytopicApp = express()

mytopicApp.get('/:uid', [mytopic.getListByUid,mytopic.getInfoByUid,mytopic.getres], (req, res) => {
    let {
        user,
        mytopics,
        info,
        getres
    } = req
    res.render('admin/mytopic/index', {
        user: user,
        mytopics: mytopics,
        info: info,
        getres: getres
    })
})

mytopicApp.post('/addAid', mytopic.addAid, (req, res) => {
    if (req.affectedRows > 0) {
        res.render('admin/alert', { code: true, title: '成功提示', message: '选题/修改成功', url: '/admin/mytopic/'+req.body.uid })
    } else {
        res.render('admin/alert', { code: true, title: '失败提示', message: '选题/修改失败', url: '/admin/mytopic/' + req.body.uid })
    }
})

module.exports = mytopicApp